--
-- Author: shunguo.chen
-- Date: 2016-08-09 14:53:14
--
-- FriendBtnMorePanel

local ClassRef = app.mvc.createPanelClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node)
	sprite:init()
	return sprite
end                    

function ClassRef:init(data)
	self.super.init(self, data)

	self._size = self._ui.choose:getContentSize()

	display.nodeRemoveForNotHit(self, function(posX,posY)
			self:performWithDelay(function() self:setVisible(false) end, 0)
		end)

	local function onBtnClick(sender)
		if self._data then
			local name = sender:getName()
			if name == "Button_view" then
				executeFunc(self._onOperate, "detail", self._data)
			elseif name == "Button_mail" then
				executeFunc(self._onOperate, "mail", self._data)
			elseif name == "Button_team" then
				executeFunc(self._onOperate, "applyIntoTeam", self._data)
			elseif name == "Button_blacklist" then
				executeFunc(self._onOperate, "addBlack", self._data.uid)
			elseif name == "Button_deletefriend" then
				executeFunc(self._onOperate, "removeFriend", self._data.uid)
			elseif name == "Button_addfriend" then
				executeFunc(self._onOperate, "addFriend", self._data.uid)
			end
		end
		self:setVisible(false)
	end

	self._ui.Button_view:addClickEventListener(onBtnClick)
	-- self._ui.Button_mail:addClickEventListener(onBtnClick)
	self._ui.Button_team:addClickEventListener(onBtnClick)
	self._ui.Button_blacklist:addClickEventListener(onBtnClick)
	self._ui.Button_deletefriend:addClickEventListener(onBtnClick)
	self._ui.Button_addfriend:addClickEventListener(onBtnClick)
end

function ClassRef:onOperate(cb)   
	self._onOperate = cb              
end

function ClassRef:setData(data)
	self._data = data
	if self._data then
		self:setVisible(true)
		self._ui.Button_deletefriend:setVisible(self._data:isFriend())
		self._ui.Button_addfriend:setVisible(self._data:isStranger())
	else
		self:setVisible(false)
	end
end

function ClassRef:getData()
	return self._data
end

function ClassRef:getSize()
	return self._size
end

return ClassRef